package com.huaboot.system.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.huaboot.commont.core.BaseResponse;
import com.huaboot.commont.core.ResultUtils;
import com.huaboot.system.convert.SysObjectStoreConvert;
import com.huaboot.system.entity.SysObjectStoreEntity;
import com.huaboot.system.service.SysObjectStoreService;
import com.huaboot.system.query.SysObjectStoreQuery;
import com.huaboot.system.vo.SysObjectStoreVO;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.huaboot.commont.page.PageResult;
import java.util.List;

/**
* 对象存储表
*
* @author ff xxx
* @since 1.0.0 2023-10-11
*/
@RestController
@RequestMapping("system/store")
@Tag(name="对象存储表")
@AllArgsConstructor
public class SysObjectStoreController {
    private final SysObjectStoreService sysObjectStoreService;

    @GetMapping("page")
    @Operation(summary = "分页")
   // @PreAuthorize("hasAuthority('system:store:page')")
    public BaseResponse<PageResult<SysObjectStoreVO>> page(SysObjectStoreQuery query){
        return ResultUtils.success(sysObjectStoreService.page(query));
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
   // @PreAuthorize("hasAuthority('system:store:info')")
    public BaseResponse<SysObjectStoreVO> get(@PathVariable("id") Long id){
        SysObjectStoreEntity entity = sysObjectStoreService.getById(id);

        return ResultUtils.success(SysObjectStoreConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
   // @PreAuthorize("hasAuthority('system:store:save')")
    public BaseResponse<?> save(@RequestBody SysObjectStoreVO vo){
        sysObjectStoreService.save(vo);

        return ResultUtils.success("新增成功");
    }

    @PutMapping
    @Operation(summary = "修改")
   // @PreAuthorize("hasAuthority('system:store:update')")
    public BaseResponse<?> update(@RequestBody  SysObjectStoreVO vo){
        sysObjectStoreService.update(vo);

        return ResultUtils.success("修改成功");
    }

    @DeleteMapping
    @Operation(summary = "删除")
   // @PreAuthorize("hasAuthority('system:store:delete')")
    public BaseResponse<?> delete(@RequestBody List<Long> idList){
        sysObjectStoreService.delete(idList);

        return ResultUtils.success("删除成功");
    }
}
